package com.cloudlead.dictionaryAction.service.impl;

import com.cloudlead.dictionaryAction.service.UserPermissionSer;
import com.cloudlead.plugin.security.service.ScPrivilegeService;
import com.cloudlead.plugin.security.service.ScResourceService;
import com.cloudlead.plugin.security.service.ScUserHasPrivilegeService;
import com.cloudlead.plugin.security.vo.ScPrivilege;
import com.cloudlead.plugin.security.vo.ScResource;
import com.cloudlead.plugin.security.vo.ScUser;
import com.cloudlead.plugin.security.vo.ScUserHasPrivilege;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/10/15.
 */
@Service
public class UserPermissionImpl implements UserPermissionSer {
    @Autowired
    ScUserHasPrivilegeService scUserHasPrivilegeService;
    @Autowired
    ScPrivilegeService scPrivilegeService;
    @Autowired
    ScResourceService scResourceService;
    @Override
    public List getUserPermission(String user) {
        ScUserHasPrivilege scUserHasPrivilege = new ScUserHasPrivilege();
        ScUser scUser = new ScUser();
        scUser.setId(user);
        scUserHasPrivilege.setScUser(scUser);
        ScPrivilege scPrivilege = new ScPrivilege();
        ScResource scResource = new ScResource();
        List<ScUserHasPrivilege> list =  scUserHasPrivilegeService.list(scUserHasPrivilege,null);
        List list_1 = new ArrayList();
        for(ScUserHasPrivilege sc : list){
           list_1.add(scResourceService.view(scPrivilegeService.view(sc.getScPrivilege().getId()).getScResource().getId()));
        }
        return  list_1;
    }
}
